home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_200 / 264_01 / bytefree.asm < prev    next >
Assembly Source File  |  1980-01-01  |  2KB  |  58 lines

  1. ; bytefree.asm
  2. ; Works with Aztec C v3.20d.
  3. ; David MacKenzie
  4. ; 09/21/87
  5.  
  6. codeseg segment para public 'code'
  7. dataseg segment para public 'data'
  8. dataseg ends
  9.     assume cs:codeseg,ds:dataseg,es:dataseg,ss:dataseg
  10.  
  11. codeseg segment
  12.  
  13. ; long disk_bytes_free(drive)
  14. ; char drive;
  15. ; Returns the number of bytes free on drive, which can be in either upper
  16. ; or lower case.
  17. ; If drive is \0, the current drive will be used.
  18. ; Returns -1 if drive is illegal.
  19.     public disk_bytes_free_
  20. disk_bytes_free_ proc    near
  21.     push    bp            ; save bp on stack
  22.     mov    bp, sp            ; save sp in bp
  23.     mov    dl, byte ptr 4[bp]
  24.     cmp    dl, 0            ; 0 -> 0 (default drive)
  25.     je    dbf_gds
  26.     cmp    dl, 'Z'            ; uppercase have lower ASCII values
  27.     jg    dbf_lowercase
  28.     sub    dl, 40h            ; map uppercase to binary, A -> 1
  29.     jmp    dbf_gds
  30. dbf_lowercase:
  31.     sub    dl, 60h            ; map lowercase to binary, a -> 1
  32. dbf_gds:
  33.     mov    ah, 36h            ; get disk space
  34.     int    21h
  35.     cmp    ax, 0ffffh
  36.     je    dbf_err            ; bad drive specifier
  37. ; returns from get disk space call:
  38. ; ax = sectors per allocation unit
  39. ; bx = number of free allocation units on drive
  40. ; cx = bytes per sector
  41. ; (dx = total number of allocation units on drive)
  42.     mul    cx            ; free disk bytes = ax * bx * cx
  43.     mul    bx            ; dxax = free disk bytes, hi-lo
  44.     mov    sp, bp            ; restore sp from bp
  45.     pop    bp            ; restore bp from stack
  46.     ret
  47. dbf_err:
  48.     mov    dx, 0ffffh
  49.     mov    sp, bp
  50.     pop    bp
  51.     ret
  52. disk_bytes_free_ endp
  53.     
  54. codeseg ends
  55. dataseg segment para public 'data'
  56. dataseg ends
  57.     end
  58.